/*
 * @Author: 小凡子 
 * @Date: 2020-12-29 15:36:23 
 * @Last Modified by: wzz
 * @Last Modified time: 2021-06-01 11:54:25
 */
//配置axios  导入
import axios from 'axios';
import qs from 'qs';
// axios.defaults.baseURL = 'http://47.93.206.13:5588';
axios.defaults.baseURL = 'http://47.102.217.22:8001';
// axios.defaults.headers.common["Authorization"] = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJOZz09Iiwic3ViIjoiYWRtaW4xIiwiaXNzIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJpYXQiOjE2MjI0NjA3MDQsImF1ZCI6InJlc3RhcGl1c2VyIiwiZXhwIjoxNjIyNjMzNTA0LCJuYmYiOjE2MjI0NjA3MDR9.6qr0d42Q7Fsv6fOIBeAg_vOYLMVjjjQTB97yA5OxsUY"
axios.interceptors.request.use(config => {
    // Do something before request is sent
    config.headers = {
        ...config.headers,
        Authorization: sessionStorage.getItem('token'),
    }
    if (config.method == 'post' && config.url !== "/user/login") {
        config.data = qs.stringify(config.data);
    }
    return config;
},
    error => {
        // Do something with request error
        return Promise.reject(error);
    });
//响应拦截器
axios.interceptors.response.use(response => {
    // Do something before response is sent
    // console.log(response, '+++');
    let res = {
        ...response,
        data: response.data.data,
        status: response.data.status,
        statusText: response.data.message,
        timestamp: response.data.timestamp
    }
    return res;
}, error => {
    // Do something with response error
    return Promise.reject(error);
});

//导出
export default axios;